home *** CD-ROM | disk | FTP | other *** search
- /* File: /u1/Kernel/MsgOps/handlerCode.c */
-
- /*
- * $Header: /u1/Eden/Source/MsgOps/RCS/HandlerCode.v Revision 1.12 84/11/28 23:03:31 schwartz Exp$
- * INTERFACE: Defined by the exported procedures.
- *
- * FUNCTION: Provides the Message Module Message Handler
- * Services.
- *
- * IMPORTS: Eden/Source/MsgOps/Types.h,
- * /u1/Eden/Source/MsgOps/MsgTypes.h,
- * /u1/Eden/ErrCodes/MMcodes.h.
- *
- * EXPORTS: MMDefineMsgHandler, MMDispatchMsg.
- * MMDGHandler, MMDefineDGHandler.
- *
- * DESIGN: The message handler routines maintain a static
- * two-dimensional array indexed by message type and
- * subtype and containing the associated disassembled
- * message handler. Eventually,
- * this design will be modified to implement a more
- * dynamic (and possibly more sparse) data structure
- * in order to be more efficient.
- *
- * $Log: /u1/Eden/Source/MsgOps/RCS/HandlerCode.v $
- * Revision 1.12 84/11/28 23:03:31 schwartz
- * Changed MMDispatchMsg() to never call MMDeallocateMsg(), since this
- * is done by all MM routines that call it after the unsuccessful return.
- *
- * Revision 1.11 83/10/14 16:37:57 mager
- * Removed Datagram level of Message Module. Increased size of message to just
- * under 1K. Changed calls to malloc and free with xalloc and xfree.
- * Removed redundant setting of ipc header.
- * Reduced initialization of messages in MMAllocateMsg.
- *
- * Revision 1.9 83/05/19 20:14:02 cady
- * Fixed MMDefineDGHandler bug.
- *
- * Revision 1.8 83/03/18 09:59:01 cady
- * Added feature to allow NULL oldhandler pointer.
- *
- * Revision 1.7 83/02/26 20:38:37 cady
- * Fixed trace levels.
- *
- * Revision 1.6 83/02/25 12:16:27 cady
- * Added new trace levels.
- *
- * Revision 1.5 83/02/24 16:40:13 cady
- * Replaced conditional debug trace with dynamic trace.
- * Added conditional Kernel compilation.
- *
- * Revision 1.4 83/02/22 12:05:58 cady
- * Replaced #if Debug with #ifdef Debug.
- *
- * Revision 1.3 83/01/31 12:36:47 cady
- * Fixed bug introduced by previous bug fix.
- *
- * Revision 1.2 83/01/29 14:44:55 cady
- * Updated message subtypes to start at 0.
- *
- * Revision 1.1 83/01/06 14:09:55 cady
- * Initial revision
- *
- * 13-Dec-1982 Initial implementation. S. Banawan.
- */
-
- /****************************************************************/
- /* Message Module Handler Library */
- /****************************************************************/
-
- #include "Kernel/h/mmCodes.h"
- #include "Kernel/h/mmMsgTypes.h"
-
- /* These macros define the valid message type and subtype indices */
- /* index values into the Handler structure AFTER they have been */
- /* extracted from the appropriate message type and subtype */
- /* fields of a message header. */
-
- /* NOTE: It seems like some of the code will fail if MINMSGTYPE or
- * MINMSGSUBTYPE are changed to non-zero values.
- */
- #define MINMSGTYPE 0
- #define MAXMSGTYPE 24
- #define MINMSGSUBTYPE 0
- #define MAXMSGSUBTYPE 30
-
- /* These macros extract the message type and subtype index */
- /* from a standard message type and subtype. Actual types and */
- /* subtypes are assigned by the 'mc' program. */
- /* Types are 32-bit integers where the most significant 16 */
- /* bits are the facility code and the least significant 16 */
- /* bits are the version. Subtypes are 32-bit integers where */
- /* the most significant 16 bits are the facility code, the */
- /* next 13 significant bits are the subtype, and the least */
- /* significant 3 bits are the structure type 'message'. */
-
- #define ExtractType(x) ( ((x) >> 16) - 1 )
- #define ExtractSubtype(x) ( ((x) & 0xfff8) >> 3 )
-
- typedef struct
- {
- HandlerPtr Handler;
-
- } HandlerRecord;
-
- static HandlerRecord HandlersArray[MAXMSGTYPE-MINMSGTYPE+1]
- [MAXMSGSUBTYPE-MINMSGSUBTYPE+1];
-
- /************************************************************/
- /* */
- /* MMDefineMsgHandler */
- /* */
- /* MMDefineMsgHandler associates the routine fMsgHandler */
- /* with the specified message type and subtype and returns */
- /* a pointer to the previously defined handler (or NULL if */
- /* none was defined). */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSK_NoMem, MMSF_BadType, */
- /* MMSF_BadSubtype. */
- /* */
- /************************************************************/
-
- KKStatus MMDefineMsgHandler( fType, /* Message Type */
- fSubtype, /* Message Subtype */
- fMsgHandler, /* Msg Handler */
- /* returns */ fOldHandler /* Old Handler */
- )
- MessageType fType;
- MessageSubtype fSubtype;
- HandlerPtr fMsgHandler;
- HandlerPtr *fOldHandler;
- {
- MessageType i;
- MessageSubtype j;
-
- MXTraceMsg(3, "MMDefineMsgHandler( 0x%08x, 0x%08x, %d )\n", fType,
- fSubtype, fMsgHandler);
-
- if ( fType == NULLMSGTYPE ) /* default for ALL messages */
- { if ( fOldHandler != NULL )
- *fOldHandler = NULL;
- for ( i = MINMSGTYPE; i <= MAXMSGTYPE; i++ )
- for ( j = MINMSGSUBTYPE; j <= MAXMSGSUBTYPE; j++ )
- {
- HandlersArray[i][j].Handler = fMsgHandler;
- }
- return (MMSS_Success);
- }
- i = ExtractType(fType);
- if ( i > MAXMSGTYPE )
- return ( MMSF_BadType);
- if ( fSubtype == NULLMSGSUBTYPE )
- { if ( fOldHandler != NULL )
- *fOldHandler = NULL;
- for ( j = MINMSGSUBTYPE; j <= MAXMSGSUBTYPE; j++ )
- {
- HandlersArray[i][j].Handler = fMsgHandler;
- }
- return (MMSS_Success);
- };
- j = ExtractSubtype(fSubtype);
- if ( j > MAXMSGSUBTYPE )
- return (MMSF_BadSubtype);
- if ( fOldHandler != NULL )
- *fOldHandler = HandlersArray[i][j].Handler;
-
- HandlersArray[i][j].Handler = fMsgHandler;
- return (MMSS_Success);
- }
-
- /************************************************************/
- /* */
- /* MMRemoveMsgHandler */
- /* */
- /* MMRemoveMsgHandler sets the message handler for the */
- /* specified message type and subtype to be undefined and */
- /* returns a pointer to the previously defined handler. */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSF_NoEntry */
- /* */
- /************************************************************/
- #if 0
- /*
- This routine has been written as a macro based on the routine
- MMDefineMsgHandler.
- */
-
- KKStatus MMRemoveMsgHandlerx( fType, /* Message Type */
- fSubtype, /* Message Subtype */
- /* returns */ fOldHandler /* Old Handler */
- )
- MessageType fType;
- MessageSubtype fSubtype;
- HandlerPtr *fOldHandler;
- {
- }
- #endif 0
-
- /****************************************************************/
- /* */
- /* MMDispatchMsg */
- /* */
- /* MMDispatchMsg extracts the message type and subtype from */
- /* the message and calls the message handler previously */
- /* identified by the MMDefineMsgHandler routine. */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSF_NoEntry, MMSF_BadType, */
- /* MMSF_BadSubtype. */
- /* */
- /****************************************************************/
-
- KKStatus MMDispatchMsg( fMsg /* Incoming message */
- )
- MessagePtr fMsg;
- {
- HandlerPtr handler;
- MessageType type;
- MessageSubtype subtype;
-
- type = ExtractType(fMsg->MsgHdr.MsgType);
- subtype = ExtractSubtype(fMsg->MsgHdr.MsgSubtype);
-
- MXTraceMsg(5, "MMDispatchMsg( 0x%05x ) type = 0x%06x, subtype = 0x%06x\n",
- fMsg, fMsg->MsgHdr.MsgType, fMsg->MsgHdr.MsgSubtype);
-
- if ( type > MAXMSGTYPE )
- return MMSF_BadType;
- if ( subtype > MAXMSGSUBTYPE )
- return MMSF_BadSubtype;
-
- handler = HandlersArray[type][subtype].Handler;
- if ( handler == NULL )
- return(MMSF_NoEntry);
- else
- {
- MXTraceMsg(5, "Calling handler 0x%x msg 0x%x\n", handler, fMsg);
- (*handler)(fMsg);
- return(MMSS_Success);
- }
- }
- /****************************************************************/
- /* End of Message Module Handler Library */
- /****************************************************************/
-